<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="./js/vue.js"></script>
    <style>
        #app {
            border: 2px solid black;
            padding: 10px;
            margin-bottom: 400px;
        }

        .child {
            margin: 20px;
            padding: 10px;
            background-color: #cccccc;
        }
    </style>

</head>
<body>
    <div id="app">
        <h3>父组件</h3>
        <input type="button" value="切换组件One" @click=" name='ChildOne' ">
        <input type="button" value="切换组件Two" @click=" name='ChildTwo' ">
        <!-- <child-one v-show=" name=='ChildOne' "></child-one>
        <child-two v-show=" name=='ChildTwo' "></child-two> -->
        <hr>
        <!-- 
            动态组件是以组件的创建和删除方式完成组件的动态切换

            keep-alive 组件用于描述 组件的缓存机制的
            被该组件包裹的 动态组件，自定义的v-if组件，自定义的v-for 都会被默认内存缓存
                => 组件一旦创建不会被销毁，除非手动调用销毁
        -->
        <!-- <keep-alive include="ChildOne,ChildTwo"> -->
        <!-- <keep-alive :include=" comp ">
            <component :is=" name "></component>
        </keep-alive> -->
        <keep-alive :exclude="/Two$/">
            <component :is=" name "></component>
        </keep-alive>
        <hr>
    </div>
    <template id="ChildOne">
        <div class="child" id="组件One">
            <h3>子组件one</h3>
        </div>
    </template>
    <template id="ChildTwo">
        <div class="child" id="组件Two">
            <h3>子组件two</h3>
        </div>
    </template>

</body>
<script>
    Vue.component("ChildOne",{
        template:"#ChildOne",
        beforeCreate() {
            console.log("ChildOne:beforeCreate")
        },
        beforeDestroy() {
            console.log("ChildOne:beforeDestory")
        },
        activated() {
            console.log("ChildOne:显示")
        },
        deactivated(){
            console.log("ChildOne:隐藏")
        }
    });
    Vue.component("ChildTwo",{
        template:"#ChildOne",
        beforeCreate() {
            console.log("ChildTwo:beforeCreate")
        },
        befoteDestroy(){
            console.log("ChildTwo:beforeDestory")
        }
    })

    new Vue({
        el:"#app",
        data:{
            name:"ChildOne",
            comp:"ChildOne,ChildTwo"
        }
    })
</script>
</html>